 
#include "uart.h"
#include "SerialServo.h"
 
uint8_t len = 0;
uint16_t times = 0;
unsigned char data[BUFFER_SIZE] = {0};

int position_array[5] = {500,500,500,500,500};
int temperature_array[5] = {0,0,0,0,0};
int volatge_array[5] = {0,0,0,0,0};

/**
 * @brief       初始化串口
 * @param       baudrate: 波特率, 根据自己需要设置波特率值
 * @note        注意: 必须设置正确的时钟源, 否则串口波特率就会设置异常.
 * @retval      无
 */
void uart0_1_init(uint32_t baudrate)
{
    uart_config_t uart_config;                          /* 串口配置句柄 */
    uart_config.baud_rate = baudrate;                   /* 波特率 */
    uart_config.data_bits = UART_DATA_8_BITS;           /* 字长为8位数据格式 */
    uart_config.parity = UART_PARITY_DISABLE;           /* 无奇偶校验位 */
    uart_config.stop_bits = UART_STOP_BITS_1;           /* 一个停止位 */
    uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;   /* 无硬件控制流 */
    uart_config.source_clk = UART_SCLK_APB;             /* 配置时钟源 */
    uart_config.rx_flow_ctrl_thresh = 122;              /* 硬件控制流阈值 */
    uart_param_config(UART0_UX, &uart_config);          /* 配置uart端口 */
    uart_param_config(UART1_UX, &uart_config);          /* 配置uart端口 */
    /* 配置uart引脚 */
    uart_set_pin(UART0_UX, UART0_TX_GPIO_PIN, UART0_RX_GPIO_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_set_pin(UART1_UX, UART1_TX_GPIO_PIN, UART1_RX_GPIO_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    /* 安装串口驱动 */
    uart_driver_install(UART0_UX, BUFFER_SIZE, BUFFER_SIZE, 0, NULL, 0);
    uart_driver_install(UART1_UX, BUFFER_SIZE, BUFFER_SIZE, 0, NULL, 0);
    uart_flush(UART0_UX);
    uart_flush(UART1_UX);
}
 
void servo_data_read()
{
    // uart_get_buffered_data_len(UART0_UX, (size_t*) &len); 
    // if(len>0)
    // {
    //     memset(data, 0, BUFFER_SIZE); //清空数组存放接收数据
    //     uart_read_bytes(UART0_UX, data, len, 100);
    //     printf("receive message:%s\r\n",data);
    //     uart_write_bytes(UART0_UX, (const char*)data, strlen((const char*)data));   /* 写数据 */
    //     uart_flush(UART0_UX);                   //清空缓冲区
    // }
    

        LobotSerialServoReadPosition(UART1_UX);
        LobotSerialServoReadVin(UART1_UX);
        LobotSerialServoReadTemp(UART1_UX);
        LobotSerialServoReadTempLimit(UART1_UX);
        LobotSerialServoReadVinLimit(UART1_UX);
}